// image转base64
export default function imgToBase64(imgUrl) {
    if(imgUrl != "") {
        let image = new Image();
        image.src = imgUrl + "?v=" + Math.random(); // 处理缓存
        image.crossOrigin = "*"; // 支持跨域图片
        return new Promise(function(resolve, reject) {
            image.onload = function() {
                // let base64 = getBase64Image(image); //调用函数并将其转为base64图片
                let canvas = document.createElement("canvas");
                    canvas.width = image.width;
                    canvas.height = image.height;
                    let ctx = canvas.getContext("2d");
                    ctx.drawImage(image, 0, 0, image.width, image.height);
                    let ext = image.src.substring(image.src.lastIndexOf(".") + 1).toLowerCase();
                    let dataURL = canvas.toDataURL("image/" + ext);
                    // return dataURL;
                    resolve(dataURL);
            };
        })
    }
}
